﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using EntityTools.Model;
using WAF.EntityFramework;

namespace EntityTools.Forms
{
    public partial class DbInfos : Form
    {
        private MainForm mainForm;

        public DbInfos(MainForm form)
        {
            InitializeComponent();

            mainForm = form;

            comboBoxType.DataSource = Enum.GetNames(typeof(WAF.DAO.DbAccess.DatabaseType));
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            DbInfo db = new DbInfo();

            db.Name     = txtName.Text.Trim();
            db.Type     = comboBoxType.Text;
            db.Server   = txtServer.Text.Trim();
            db.DbName   = txtDbName.Text.Trim();
            db.Account  = txtUserName.Text.Trim();
            db.Password = txtPassword.Text.Trim();
            db.Remark   = txtRemark.Text.Trim();

            long newDbID = EntityAction.Insert(db);

            TreeNode node = new TreeNode();
            node.Name = newDbID.ToString();
            node.Text = db.Name;
            mainForm.GetTreeView().Nodes.Add(node);

            this.Close();
        }
    }
}
